﻿#region Namespace References

using System;
using System.Collections.Generic;

#endregion

namespace DynConDevCorp.OpenArch.SmartData.Persistance
{
    internal class PersistanceMetadataManager
    {
        #region Constructors

        private PersistanceMetadataManager()
        {
        }

        #endregion

        #region Public Static Properties

        public static PersistanceMetadataManager GlobalInstance
        {
            get { return s_GlobalInstance; }
        }

        #endregion

        #region Public Instance Methods

        public PersistanceMetadata GetMetadata<TEntity>()
        {
            return GetMetadata(typeof (TEntity));
        }


        public PersistanceMetadata GetMetadata(Type entityType)
        {
            PersistanceMetadata retVal;
            if (!m_MetaDictionary.TryGetValue(entityType, out retVal))
            {
                retVal = new PersistanceMetadata(entityType);
                SetMetadata(entityType, retVal);
            }
            return retVal;
        }


        public void SetMetadata(Type entityType, PersistanceMetadata metadata)
        {
            m_MetaDictionary[entityType] = metadata;
        }

        #endregion

        #region Fields and Constants

        private static readonly PersistanceMetadataManager s_GlobalInstance = new PersistanceMetadataManager();

        private readonly Dictionary<Type, PersistanceMetadata> m_MetaDictionary =
            new Dictionary<Type, PersistanceMetadata>();

        #endregion
    }
}